package eu.dzhw.fdz.metadatamanagement.ordermanagement.domain;

import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import eu.dzhw.fdz.metadatamanagement.common.domain.AbstractRdcDomainObject;
import eu.dzhw.fdz.metadatamanagement.common.domain.Counter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * Order (DTO) containing all relevant information for ordered {@link Product}s.
 */
@Document(collection = "orders")
@EqualsAndHashCode(callSuper = false, of = "id")
@ToString(callSuper = true)
@NoArgsConstructor
@Data
@AllArgsConstructor
@Builder
@Schema(
    description = "Go <a href='https://dzhw.github.io/metadatamanagement/"
    + "eu/dzhw/fdz/metadatamanagement/ordermanagement/domain/Order.html'>here</a>"
    + " for further details.")
public class Order extends AbstractRdcDomainObject {

  private static final long serialVersionUID = 8058350737401818558L;

  /**
   * The id of an order. It is a number which is generated by a sequence (see {@link Counter}.
   */
  @Id
  private String id;

  /**
   * The key of the preferred language (either "de" or "en") of the customer.
   *
   * Must not be empty.
   */
  @NotEmpty
  private String languageKey;

  /**
   * The current state of the order. One of {@link OrderState}.
   */
  @Indexed
  @NotNull
  private OrderState state;

  /**
   * The id of the client (one of @link {@link OrderClient}) who has last modified this order.
   */
  @Indexed
  @NotNull
  private OrderClient client;

  /**
   * List of data {@link Product}s the customer want to order.
   *
   * Must not be empty.
   */
  @Valid
  private List<Product> products;
}
